/**
* @author Yangbo zhou 2008-11-12 14:11 
*/
package com.icid.store.util
{
	import flash.events.Event;
	import flash.events.ProgressEvent;
	
	import mx.controls.Image;
	import mx.controls.ProgressBar;
	import mx.controls.ProgressBarMode;

	public class ImageWithProgressBar extends Image
	{
		private var _progressBar:ProgressBar;
		public function ImageWithProgressBar()
		{
			super();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			addEventListener(ProgressEvent.PROGRESS,function(event:ProgressEvent):void
			{
				_progressBar.setProgress(event.bytesLoaded,event.bytesTotal);
				_progressBar.visible = event.bytesLoaded<event.bytesTotal;
			});
			
			addEventListener(Event.COMPLETE,function(event:Event):void
			{
				_progressBar.visible = false;
			});
			
			_progressBar = new ProgressBar();
			_progressBar.mode = ProgressBarMode.MANUAL;
			_progressBar.percentWidth = 100;
			_progressBar.setStyle("horizontalCenter","0");
			_progressBar.setStyle("verticalCenter","0");
			addChild(_progressBar);
			_progressBar.visible = false;
		}
		
	}
}